%%-----------------------------------------------------------------------%%
%%--- Polar Coordinates and Trigonometric Integrals ---------------------%%

\chapter{Polar Coordinates and Trigonometric Integrals}
\index{polar coordinates}

The rectangular coordinate system is immensely useful, but it is not
the only way to assign an address to a point in the plane and
sometimes it is not the most useful. In applications to physical
problems where there is some ``cylindrical symmetry,'' such as a
vibrating drum or water moving along a pipe, the most natural
coordinates are often polar coordinates rather than rectangular
coordinates.

In many experimental situations, our location is fixed and we, using
sonar or radar, take readings in different
directions~(Figure~\ref{fig:9-1-2}). This information can be graphed
using rectangular coordinates, e.g. with the angle on the horizontal
axis and the measurement on the vertical axis.
%
\begin{figure}[!htbp]
\centering
\includegraphics[height=4cm,width=13cm]{graphs/fig9-1-1.eps}
\caption{Sonar and radar use polar coordinates.}
\label{fig:9-1-1}
\end{figure}
%
However, sometimes it is more useful to plot the information in a way
similar to the way in which it was collected, as magnitudes along
radial lines~(Figure~\ref{fig:9-1-2}). This system is called the polar
coordinate system.

\begin{figure}[!htbp]
\centering
\includegraphics[height=4cm,width=5cm]{graphs/fig9-1-2.eps}
\caption{Polar coordinate system.}
\label{fig:9-1-2}
\end{figure}

\begin{example}
\label{ex:polar:polar_coordinates_SOS}
SOS! You have just received a distress signal from a ship located at
point $A$ on your radar screen~(see Figure~\ref{fig:9-1-3}). Describe
its location to your captain so your vessel can speed to the rescue.
\end{example}

\begin{figure}[!htbp]
\centering
\includegraphics[height=5cm,width=10cm]{graphs/fig9-1-3.eps}
\caption{A distress signal from sea.}
\label{fig:9-1-3}
\end{figure}

\begin{proof}[Solution]
You could convert the relative location of the other ship to
rectangular coordinates. Then tell your captain to go due east for
7.5~miles and north for 13~miles, but that certainly is not the
quickest way to reach the other ship. It is better to tell the captain
to sail for 15~miles in the direction of $60^{\circ}$. If the
distressed ship was at $B$ on the radar screen, your vessel should
sail for 10~miles in the direction $150^{\circ}$. (Real radar screens
have $0^{\circ}$ at the top of the screen, but the convention in
mathematics is to put $0^{\circ}$ in the direction of the positive
$x$-axis and to measure positive angles counterclockwise from
there. Of course a real sailor speaks of ``bearing'' and ``range''
instead of direction and magnitude.)
\end{proof}

\begin{practice}
Describe the locations of the ships at $C$ and $D$ in
Figure~\ref{fig:9-1-3} by giving a distance and a direction to those
ships from your current position at the center of the radar screen.
\end{practice}


%%-----------------------------------------------------------------------%%
%%--- Polar coordinates -------------------------------------------------%%

\section{Polar coordinates}
\label{sec:polar_coordinates}
\index{polar coordinates}

Polar coordinates allow us to describe a point $(x, y)$ in the plane
in a different way, namely
\[
(x, y) \longleftrightarrow (r, \theta)
\]
where $r$ is any real number and $\theta$ is an angle. To construct a
polar coordinate system, we need a starting point~(called the origin
or pole) for the magnitude measurements and a starting
direction~(called the polar axis) for the angle measurements. A
\emph{polar coordinate pair} for a point $P$ in the plane is an
ordered pair $(r, \theta)$, where $r$ is the directed distance along a
radial line from $O$ to $P$, and $\theta$ is the angle formed by the
polar axis and the segment $OP$. The angle $\theta$ is positive when
the angle of the radial line $OP$ is measured counterclockwise from
the polar axis, and $\theta$ is negative when measured clockwise.

Either degree or radian measure can be used for the angle in the
polar coordinate system. However, when we differentiate and integrate
trigonometric functions of $\theta$, we will \emph{always} want all of
the angles to be given in \emph{radian measure}.\index{radian} From
now on, we will primarily use radian measure.
\emph{You should assume that all angles are given in radian measure
unless the units ``$\, ^{\circ}$''~(``degrees'') is shown.}

In the rectangular coordinate system, the derivative $dy / dx$ measures
both the rate of change of $y$ with respect to $x$ and the slope of
the tangent line. In the polar coordinate system, $dr / d\theta$
measures the rate of change of $r$ with respect to $\theta$~(see
Figure~\ref{fig:9-2-1}). The sign of $dr / d\theta$ tells us whether
$r$ is increasing or decreasing as $\theta$ increases.

\begin{figure}[!htbp]
\centering
\includegraphics[height=4cm,width=6cm]{graphs/fig9-2-1.eps}
\caption{The value $r$ changing as a function of $\theta$.}
\label{fig:9-2-1}
\end{figure}

Polar coordinates are extremely useful, especially when thinking about
complex numbers. Note that the $(r, \theta)$ representation of a point
is not unique. First, $\theta$ is not determined by the point. We
could add $2\pi$ to it and get the same point:
\[
\left( 2, \frac{\pi}{4} \right)
=
\left( 2, \frac{9\pi}{4} \right)
=
\left( 2, \frac{\pi}{4} + 389 \cdot 2\pi \right)
=
\left( 2, \frac{-7\pi}{4} \right).
\]
Also, $r$ can be negative, which also makes the representation
$(r, \theta)$ non-unique:
\[
\left( 1, \frac{\pi}{2} \right)
=
\left( -1, \frac{3\pi}{2} \right).
\]
Think about this as follows: facing in the direction $3\pi/2$ and
backing up 1~meter gets you to the same point as looking in the
direction $\pi/2$ and walking forward 1~meter.

We can convert back and forth between Cartesian and polar
coordinates using the formulas
%
\begin{align}
\label{eqn:polar:polar_to_Cartesian}
x &=r \cos(\theta) \\
y &=r \sin(\theta)
\end{align}
and in the other direction
%
\begin{align}
\label{eqn:polar:Cartesian_to_polar}
r^2 &= x^2 + y^2 \\
\tan(\theta) &= \frac{y}{x}.
\end{align}
Thus $r = \pm \sqrt{x^2 + y^2}$ and $\theta = \tan^{-1}(y/x)$. This
conversion is illustrated in
Figure~\ref{fig:polar:Cartesian_polar_conversion}.

\begin{figure}[!htbp]
\centering
\includegraphics[height=4cm,width=13cm]{graphs/fig9-1-19.eps}
\caption{Conversion between rectangular and polar coordinates.}
\label{fig:polar:Cartesian_polar_conversion}
\end{figure}

\begin{table}[!htbp]
\centering
\begin{tabular}{|l|l|} \hline
0              & $\sin(0) = 0$                       \\
$\pi/6$        & $\sin(\pi/6) = 1/2$                 \\
$\pi/4$        & $\sin(\pi/4) =\frac{\sqrt{2}}{2}$   \\
$\pi/2$        & $\sin(\pi/2) = 1$                   \\
$3\pi/4$       & $\sin(3\pi/4) = \frac{\sqrt{2}}{2}$ \\
$\pi$          & $\sin(\pi) = 0$                     \\
$\pi + \pi/6$  & $\sin(\pi+\pi/6) = -1/2$            \\\hline
\end{tabular}
\caption{Values of $r = \sin(\theta)$ for one period.}
\label{tab:polar:one_period_sin}
\end{table}

\begin{example}
Sketch $r = \sin(\theta)$, which is a circle sitting on top of the
$x$-axis.
\end{example}

\begin{figure}[h!]
\centering
\subfigure[]{
\includegraphics[height=5cm,width=6cm]{graphs/sage-polar1.eps}
}\quad
\subfigure[]{
\includegraphics[height=5cm,width=6cm]{graphs/sage-polar2.eps}
}
\caption{Plot of (a)~$r = 1$ for $0 < \theta < \pi/6$; and
  (b)~$r = \sin(\theta)$ for $0 < \theta < 2\pi$.}
\label{fig:polar:fixed_and_varying_r}
\end{figure}

\begin{proof}[Solution]
We plug in points for one period of the function we are
graphing, in this case $[0, 2\pi]$. The points are shown in
Table~\ref{tab:polar:one_period_sin}. Notice it is nice to allow $r$
to be negative, so we do not have to restrict the input. But it is
really painful to draw this graph by hand.

To more accurately draw the graph, let's try converting the equation
to one involving polar coordinates. This is easier if we multiply both
sides by $r$:
\[
r^2 = r\sin(\theta).
\]
The new equation has the extra solution
$(r=0,\, \theta=\text{anything})$ so we have to be careful not to
include this point. Now convert to Cartesian coordinates
using~(\ref{eqn:polar:polar_to_Cartesian}) to
obtain~(\ref{eqn:polar:Cartesian_to_polar}):
%
\begin{equation}
\label{eqn:polar:x2_y2_y}
x^2 + y^2 = y.
\end{equation}
%
The graph of~(\ref{eqn:polar:x2_y2_y}) is the same as that of
$r = \sin(\theta)$. To confirm this, we complete the square:
%
\begin{align*}
x^2 + y^2         &= y   \\
x^2 + y^2 - y     &= 0   \\
x^2 + (y - 1/2)^2 &= 1/4.
\end{align*}
%
Thus the graph of~(\ref{eqn:polar:x2_y2_y}) is a circle of radius
$1/2$ centered at $(0, 1/2)$.
\end{proof}

Actually \emph{any} polar graph\index{polar graph} of the form
$r = a\sin(\theta) + b\cos(\theta)$ is a circle (exercise for the
interested reader).


%%-----------------------------------------------------------------------%%
%%--- Areas in polar coordinates ----------------------------------------%%

\section{Areas in polar coordinates}
\index{area!polar coordinates}

Section~\ref{sec:polar_coordinates} introduced the polar coordinate
system and discussed how to plot points, how to create graphs of
functions (from data, a rectangular graph, or a formula), and how to
convert back and forth between the polar and rectangular coordinate
systems. This section examines calculus in polar coordinates: rates of
changes, slopes of tangent lines, areas, and lengths of curves. The
results we obtain may look different, but they all follow from the
approaches used in the rectangular coordinate system.

We know how to compute the area of a sector, i.e. piece of a circle
with angle $\theta$. This is the basic polar region whose area is
\[
A
=
\text{(fraction of the circle)} \cdot \text{(area of circle)}
=
\left( \frac{\theta}{2\pi} \right) \cdot \pi r^2
=
\frac{1}{2} r^2 \theta.
\]

We now imitate what we did before with Riemann sums. We chop up,
approximate, and take a limit. Break the interval of angles from $a$
to $b$ into $n$ subintervals. Choose $\theta_i^*$ in each
interval. The area of each slice is approximately
$(1/2) f(\theta_i^*)^2 \theta_i^2$. Thus
\[
A
=
\text{Area of shaded region}
\approx
\sum_{i=1}^n \frac{1}{2} f(\theta_i^*)^2 \Delta(\theta).
\]
Taking the limit, we see that
%
\begin{equation}
\label{eqn:polar:area_polar_coordinates}
A
=
\lim_{n \to \infty} \sum_{i=1}^n \frac{1}{2} f(\theta_i^*)^2 \Delta(\theta)
=
\frac{1}{2} \cdot \int_a^b f(\theta)^2 \, d\theta.
\end{equation}
%
Amazing! By understanding the definition of Riemann sum, we have
derived a formula for areas swept out by a polar graph. But does it
work in practice?

\begin{figure}[!htbp]
\centering
\includegraphics[height=4cm,width=12cm]{graphs/sage-polar4.eps}
\caption{Graph of $y = \cos(2x)$ and $r = \cos(2\theta)$.}
\label{fig:polar4}
\end{figure}

\begin{example}
Find the area enclosed by one leaf of the four-leaved rose
$r = \cos(2\theta)$ shown in Figure~\ref{fig:polar4}.
%\figtwo{Graph of $y=\cos(2x)$ and $r=\cos(2\theta)$}%
%{example_4rosecos}{example_4rose}
%sage: gnuplot.plot('set polar; plot [0:2*pi] cos(2*t)', 'example_4rose')
%sage: gnuplot.plot('plot [0:2*pi] cos(2*x)', 'example_4rosecos')
\end{example}

\begin{proof}[Solution]
The graph in Figure~\ref{fig:polar4} is plotted using these commands:
%
\begin{center}
\fontsize{10pt}{10pt}
\selectfont
\tt
\begin{lstlisting}
sage: P1 = polar_plot(lambda x: cos(2*x), 0, 2*pi, rgbcolor=(0,0,1))
sage: P2 = plot(lambda x: cos(2*x), 0, 2*pi, rgbcolor=(1,0,0), linestyle=":")
sage: show(P1 + P2)
\end{lstlisting}
\end{center}
%
To find the area using the methods we know so far, we would need to
find a function $y = f(x)$ that gives the ``height'' of the leaf.

Multiplying both sides of the equation $r = \cos(2\theta)$ by $r$
yields
\[
r^2
=
r\cos(2\theta)
=
r(\cos^2 \theta - \sin^2 \theta)
=
\frac{1}{r} \big( (r\cos\theta)^2 - (r\sin\theta)^2 \big).
\]
Because $r^2 = x^2 + y^2$, $x = r\cos(\theta)$, and $y = r\sin(\theta)$,
we have
\[
x^2 + y^2
=
\frac{1}{\sqrt{x^2 + y^2}} (x^2 - y^2).
\]
Solving for $y$ is a crazy mess, and then integrating? It seems
impossible! But it is not impossible if we remember the basic idea of
integral calculus: integral equals area.

We need the boundaries of integration to determine the area. Start at
$\theta = -\pi/4$ and go to $\theta = \pi/4$. As a check, note that
$\cos((-\pi/4) \cdot 2) = 0 = \cos((\pi/4) \cdot 2)$. We evaluate
%
\begin{align*}
\frac{1}{2} \cdot \int_{-\pi/4}^{\pi/4} \cos(2\theta)^2 \, d\theta
&= \int_0^{\pi/4} \cos(2\theta)^2 \, d\theta \qquad \text{(even function)} \\
&= \frac{1}{2} \int_0^{\pi/4} (1 + \cos(4\theta)) \, d\theta \\
&= \frac{1}{2} \left[
  \theta + \frac{1}{4} \cdot \sin(4\theta) \right]_0^{\pi/4} \\
&= \frac{\pi}{8}.
\end{align*}
%
We used
%
\begin{equation}
%% \label{eqn:polar:cos_2_sin_2}
\cos^2(x) = (1 + \cos(2x)) / 2
\qquad\text{and}\qquad
\sin^2(x) = (1 - \sin(2x)) / 2
\end{equation}
which follow from
\[
\cos(2x)
=
\cos^2(x) - \sin^2(x)
=
2\cos^2(x) - 1
=
1 - 2\sin^2(x).
\]
Therefore, by~(\ref{eqn:polar:area_polar_coordinates}), the area is
$A = \frac{\pi}{8}$ .
\end{proof}

\begin{figure}[!htbp]
\centering
\includegraphics[height=6cm,width=10cm]{graphs/sage-polar5.eps}
\caption{Graph of $r = 3\cos(x)$ and $r = 1 + \cos(\theta)$.}
\label{fig:polar:3costheta_cardiod}
\end{figure}

\begin{example}
Find the area of the regions inside the curve $r = 3\cos(\theta)$ and
outside the cardiod curve $r = 1 + \cos(\theta)$.
%\fig{Graph of $r=3\cos(\theta)$ and $r=1+\cos(\theta)$}{example_card}
%sage: gnuplot.plot('set polar; plot [0:2*pi] 3*cos(t), 1+cos(t)', 'example_card')
\end{example}

\begin{proof}[Solution]
The two curves are shown in Figure~\ref{fig:polar:3costheta_cardiod}
and plotted using these commands:
%
\begin{center}
\fontsize{10pt}{10pt}
\selectfont
\tt
\begin{lstlisting}
sage: P1 = polar_plot(lambda x: 3*cos(x), 0, 2*pi, rgbcolor=(0,0,1))
sage: P2 = polar_plot(lambda x: 1 + cos(x), 0, 2*pi, rgbcolor=(1,0,0), linestyle=":")
sage: show(P1 + P2)
\end{lstlisting}
\end{center}
%
The process for computing the area is the same as before. It is the
difference of two areas. Figure out the limits, which are where the
curves intersect, i.e. the value of $\theta$ such that
\[
3\cos(\theta)
=
1 + \cos(\theta).
\]
Solving for $1$, we get $2\cos(\theta) = 1$ so $\cos(\theta) = 1/2$,
hence $\theta = \pi/3$ and $\theta = -\pi/3$. Thus the area is
%
\begin{align*}
A
&= \frac{1}{2} \int_{-\pi/3}^{\pi/3}
   (3\cos(\theta))^2 - (1 + \cos(\theta))^2 \, d\theta \\
&= \int_0^{\pi/3} (3\cos(\theta))^2 -
   (1 + \cos(\theta))^2 \, d\theta
\end{align*}
%
since the integrand is an even function. Now expand this out
algebraically and integrate term-by-term:
%
\begin{align*}
\int_0^{\pi/3} (3\cos(\theta))^2 - (1 + \cos(\theta))^2 \, d\theta
&= \int_0^{\pi/3} (8\cos^2(\theta) - 2\cos(\theta) - 1) \, d\theta \\
&= \int_0^{\pi/3} \left(
   8 \cdot \frac{1}{2} \big( 1 + \cos(2\theta) \big)
   -2 \cos(\theta) -1 \right) \, d\theta \\
&= \int_0^{\pi/3} 3 + 4 \cos(2\theta) - 2\cos(\theta) \, d\theta \\
&= \Bigl[ 3\theta + 2 \sin(2\theta) - 2\sin(\theta) \Bigr]_0^{\pi/3} \\
&= \pi + 2\cdot \sqrt{\frac{3}{2}} -
   2\sqrt{\frac{3}{2}} - 0 - 2\cdot 0 - 2 \cdot 0
\end{align*}
%
which simplifies to $\pi$.
\end{proof}

\begin{figure}[!htbp]
\centering
\includegraphics[height=5cm,width=4cm]{graphs/fig9-2-19.eps}
\caption{Graph of $r = \theta$.}
\label{fig:9-2-19}
\end{figure}

\begin{practice}
Compute the area of the shaded region in Figure~\ref{fig:9-2-19}.
\end{practice}


%%-----------------------------------------------------------------------%%
%%--- Complex numbers ---------------------------------------------------%%

\section{Complex numbers}
\index{complex numbers}

A complex number is an expression of the form $z = a + bi$, where $a$
and $b$ are real numbers, and $i^2 = -1$. The number $a$ is the
\emph{real part}\index{real part} of $z$ and $b$ is the
\emph{imaginary part}.\index{imaginary part} We add and multiply
complex numbers as follows:
%
\begin{align*}
(a + bi) + (c + di)     &= (a + c) + (b + d)i \\
(a + bi) \cdot (c + di) &= (ac - bd) + (ad + bc)i.
\end{align*}
%
The \emph{complex conjugate}\index{complex conjugate} of a complex
number is
\[
\overline{a + bi} = a - bi.
\]
Note that
\[
(a + bi) (\overline{a + bi}) = a^2 + b^2
\]
is a real number (has no complex part).

If $c + di \neq 0$, then
\[
\frac{a + bi}{c + di}
=
\frac{(a + bi)(c - di)}{c^2 + d^2}
=
\frac{1}{c^2 + d^2}((ac + bd) + (bc - ad)i).
\]

\begin{example}
Simplify the expressions $(1 - 2i)(8 - 3i)$ and $1 / (1 + i)$ using
complex multiplication and division.
\end{example}

\begin{proof}[Solution]
Using the rule for multiplication of complex numbers, we have
$(1 - 2i)(8 - 3i) = 2 - 19i$. Now using the rule for complex division,
we get $1 / (1 + i) = (1 - i) / 2 = 1/2 - (1/2) i$.
\end{proof}

Complex numbers are incredibly useful in providing better ways to
understand ideas in calculus and more generally in many applications
(e.g. electrical engineering, quantum mechanics, fractals, etc.). For
example,
%
\begin{itemize}
\item Every polynomial $f(x)$ \emph{factors} as a product of linear
  factors $(x - \alpha)$, if we allow the $\alpha$'s in the
  factorization to be complex numbers. For example,
  \[
  f(x) = x^2 + 1 = (x - i)(x + i).
  \]
  This will provide an easier to use variant ofthe
  ``partial fractions'' integration technique, which we will see
  later.

\item Complex numbers are in \emph{correspondence} with points in the
  plane via the rule
  \[
  (x, y) \longleftrightarrow x + iy.
  \]
  With this correspondence, we obtain a way to add and \emph{multiply}
  points in the plane.

\item Similarly, points in \emph{polar coordinates} correspond to
  complex numbers:
  \[
  (r, \theta) \longleftrightarrow r (\cos(\theta) + i \sin(\theta)).
  \]

\item Complex numbers provide a very nice way to remember and
  \emph{understand trigonometric identities}.
\end{itemize}


%%-----------------------------------------------------------------------%%
%%--- Polar form --------------------------------------------------------%%

\subsection{Polar form}
\index{polar form}

%% Consider introducing the abbreviation "cis\theta" for
%% cos\theta + i sin\theta.

The \emph{polar form} of a complex number $x + iy$ is
$r(\cos(\theta) + i\sin(\theta))$, where $(r, \theta)$ is any choice
of polar coordinates that represent the point $(x, y)$ in rectangular
coordinates. Recall that you can find the polar form of a point using
\[
r = \sqrt{x^2 + y^2}
\quad\text{and}\quad
\theta = \tan^{-1}(y/x).
\]
Historically, the ``existence'' of complex numbers was not generally
accepted until people got used to a geometric interpretation of them.

\begin{example}
Find the polar form of $1 + i$.
\end{example}

\begin{proof}[Solution]
We have $r = \sqrt{2}$, so
\[
1 + i
=
\sqrt{2} \left( \frac{1}{\sqrt{2}} + \frac{i}{\sqrt{2}} \right)
=
\sqrt{2} \left( \cos(\pi/4) +  i \sin(\pi/4) \right).
\]
The polar form of $1 + i$ is therefore
$\sqrt{2} \left( \cos(\pi/4) +  i \sin(\pi/4) \right)$.
\end{proof}

\begin{example}
Find the polar form of $\sqrt{3} - i$.
\end{example}

\begin{figure}[!htbp]
\centering
\includegraphics[height=5cm,width=5cm]{graphs/sage-complex1.eps}
\caption{Plot of $\sqrt{3} - i$ as a directed line segment.}
\label{fig:polar:complex_number_as_vector}
\end{figure}

\begin{proof}[Solution]
We have $r = \sqrt{3 + 1} = 2$, so
\[
\sqrt{3} - i
=
2 \left( \frac{\sqrt{3}}{2} + i\frac{-1}{2} \right)
=
2 \left( \cos(-\pi/6) + i \sin(-\pi/6) \right)
\]
A plot of $\sqrt{3} - i$ as a directed line segment is shown in
Figure~\ref{fig:polar:complex_number_as_vector}. This plot is produced
using the commands:
%
\begin{center}
\fontsize{10pt}{10pt}
\selectfont
\tt
\begin{lstlisting}
sage: P1 = circle((0,0), 2)
sage: P2 = arrow((0,0), (sqrt(3), -1))
sage: P3 = text("$\sqrt{3} - i$", (2,-1))
sage: P4 = text("$-i$", (0.2,-1))
sage: P5 = text("$i$", (0.2,1))
sage: show(P1 + P2 + P3 + P4 + P5)
\end{lstlisting}
\end{center}
Directed line segments can be described using vector
notation. Chapter~\ref{chap:vectors_geometry} provides a relationship
between complex numbers and vectors.\index{vector}
\end{proof}

Finding the polar form of a complex number is exactly the same problem
as finding polar coordinates of a point in rectangular coordinates.
The only hard part is figuring out what $\theta$ is.

If we write complex numbers in rectangular form, their sum is easy to
compute:
\[
(a + bi) + (c + di)
=
(a + c) + (b + d)i.
\]
The beauty of polar coordinates is that if we write two complex
numbers in polar form, then their \emph{product} is very easy to
compute:
\[
r_1 (\cos(\theta_1) + i \sin(\theta_1)) \cdot
r_2 (\cos(\theta_2) + i \sin(\theta_2))
=
(r_1 r_2) (\cos(\theta_1+\theta_2) + i \sin(\theta_1 + \theta_2)).
\]
The magnitudes multiply and the angles add. The above formula is true
because of the double angle identities for $\sin$ and $\cos$:
%
\begin{align*}
& (\cos(\theta_1) + i \sin(\theta_1)) \cdot
    (\cos(\theta_2) + i \sin(\theta_2)) \\
&= (\cos(\theta_1)\cos(\theta_2) - \sin(\theta_1)\sin(\theta_2))
   + i (\sin(\theta_1)\cos(\theta_2) + \cos(\theta_1)\sin(\theta_2)) \\
&= \cos(\theta_1 + \theta_2) + i\sin(\theta_1 + \theta_2).
\end{align*}
%
For example, the power of a complex number in polar form is easy to
compute: just power the $r$ and multiply the angle.

\begin{theorem}
\textbf{De Moivre's Theorem.}
\index{De Moivre's Theorem}
For any integer $n$ we have
\[
(r (\cos(\theta) + i\sin(\theta)))^n
=
r^n (\cos(n \theta) + i\sin(n \theta)).
\]
\end{theorem}

\begin{example}
Compute $(1 + i)^{2006}$.
\end{example}

\begin{proof}[Solution]
Using De Moivre's Theorem, we have
%
\begin{align*}
(1 + i)^{2006}
&= (\sqrt{2} \left( \cos(\pi/4) +  i \sin(\pi/4) \right))^{2006} \\
&= \sqrt{2}^{2006} \left( \cos(2006 \pi/4) +  i \sin(2006 \pi/4) \right) \\
&= 2^{1003} \left( \cos(3\pi/2) +  i \sin(3\pi/2) \right) \\
&= -2^{1003} i
\end{align*}
%
To get $\cos(2006 \pi/4) = \cos(3\pi/2)$, we use $2006/4 = 501.5$. By
periodicity of cosine, we have
\[
\cos(2006 \pi/4)
=
\cos((501.5) \pi - 250(2\pi))
=
\cos(1.5\pi).
\]
This simplifies to $\cos(3\pi/2)$.
\end{proof}

Here is a quick summary of what we have just covered. Given a point
$(x, y)$ in the plane, we can also view it as $x + iy$ or in polar
form as $r(\cos(\theta) + i \sin(\theta))$. Polar form is great since
it is good for multiplication, powering, and for extracting roots:
\[
r_1(\cos(\theta_1) + i \sin(\theta_1))
r_2(\cos(\theta_2) + i \sin(\theta_2))
=
(r_1 r_2) (\cos(\theta_1 + \theta_2) + i \sin(\theta_1 + \theta_2)).
\]
(If you divide, you subtract the angle.) The point is that the polar
form \emph{works better} with multiplication than the rectangular form.
For any integer $n$, we have
\[
(r (\cos(\theta) + i\sin(\theta)))^n
=
r^n (\cos(n \theta) + i\sin(n \theta)).
\]

Since we know how to raise a complex number in polar form to the
$n$-th power, we can find all numbers with a given power, hence find
the $n$-th root of a complex number.

\begin{proposition}
\label{prop:polar:nth_root}
\textbf{$n$-th root.}
\index{$n$-th root}
A complex number $z = r(\cos(\theta) + i\sin(\theta))$ has $n$
distinct $n$-th roots:
\[
r^{1/n} \left(
\cos \left(\frac{\theta + 2\pi k}{n} \right)
+ i\sin \left( \frac{\theta + 2\pi k}{n} \right) \right)
\]
for $k = 0, 1, \dots, n-1$. Here $r^{1/n}$ is the real positive $n$-th
root of $r$.
\end{proposition}

As a double-check, note that by De Moivre's Theorem, each number
listed in Proposition~\ref{prop:polar:nth_root} has $n$-th power equal
to $z$.

An application of De Moivre's Theorem is to computing $\sin(n\theta)$
and $\cos(n\theta)$ in terms of $\sin(\theta)$ and $\cos(\theta)$.
For example,
%
\begin{align*}
\cos(3 \theta) + i\sin(3 \theta)
&= (\cos(\theta) + i\sin(\theta))^3 \\
&= (\cos(\theta)^3 - 3\cos{}(\theta)\sin(\theta)^2) +
   i(3\cos(\theta)^2\sin(\theta) - \sin(\theta)^3).
\end{align*}
%
Equate real and imaginary parts to get formulas for $\cos(3\theta)$
and $\sin(3\theta)$. In the next section, we will discuss going in the
other direction, i.e. writing powers of $\sin$ and $\cos$ in terms of
$\sin$ and $\cos$.

\begin{example}
Find the cube roots of $2$.
\end{example}

\begin{proof}[Solution]
Write $2$ in polar form as
\[
2 = 2 (\cos(0) + i \sin(0)).
\]
Then the three cube roots of $2$ are
\[
2^{1/3} (\cos(2\pi k/3) + i\sin(2\pi k/3))
\]
for $k = 0,1,2$. That is,
\[
2^{1/3},\quad
2^{1/3}(-1/2 + i \sqrt{3}/2),\quad
2^{1/3}(-1/2 - i \sqrt{3}/2)
\]
are the three cube roots of $2$.
\end{proof}


%%-----------------------------------------------------------------------%%
%%--- Complex exponentials and trigonometric identities -----------------%%

\section{Complex exponentials and trigonometric identities}
\index{complex exponentials}
\index{trigonometry!identities}

Recall that
%
\begin{equation}
\label{eqn:polar:angles_add}
r_1 (\cos(\theta_1) + i \sin(\theta_1))
r_2 (\cos(\theta_2) + i \sin(\theta_2))
=
(r_1 r_2) (\cos(\theta_1 + \theta_2) + i \sin(\theta_1 + \theta_2)).
\end{equation}
%
Notice that the angles add. You have seen something similar before:
\[
e^a e^b = a^{a + b}.
\]
This connection between exponentiation and~(\ref{eqn:polar:angles_add})
gives us an idea.

If $z = x + iy$ is a complex number, \emph{define}
\[
e^z = e^x(\cos(y) + i\sin(y)).
\]
We have just written polar  coordinates in another form.  It is a
shorthand for the polar form of a complex number:
\[
r(\cos(\theta) + i\sin(\theta)) = re^{i\theta}.
\]

\begin{theorem}
If $z_1$ and $z_2$ are two complex numbers, then
\[
e^{z_1} e^{z_2} = e^{z_1 + z_2}
\]
\end{theorem}

\begin{proof}
The proof is straightforward:
%
\begin{align*}
e^{z_1} e^{z_2}
&= e^{a_1} (\cos(b_1) + i\sin(b_1)) \cdot
   e^{a_2} (\cos(b_2) + i\sin(b_2)) \\
&= e^{a_1 + a_2} (\cos(b_1 + b_2) + i\sin(b_1 + b_2)) \\
&= e^{z_1 + z_2}.
\end{align*}
%
Here, we have just used~(\ref{eqn:polar:angles_add}).
\end{proof}

The following theorem is amazing, since it involves calculus.

\begin{theorem}
\label{thm:polar:e_differentiation}
If $w$ is a complex number, then
\[
\frac{d}{dx} e^{w x} = w e^{wx}
\]
for $x$ real. In fact, this is also true for $x$ a complex variable
(but we have not defined differentiation for complex variables yet).
\end{theorem}

\begin{proof}
Write $w = a + bi$. Then
%
\begin{align*}
\frac{d}{dx} e^{w x}
&= \frac{d}{dx} e^{ax + bix} \\
&= \frac{d}{dx} (e^{ax} (\cos(bx) + i \sin(bx))) \\
&= \frac{d}{dx} (e^{ax} \cos(bx) + i e^{ax}\sin(bx)) \\
&= \frac{d}{dx} (e^{ax} \cos(bx)) + i \frac{d}{dx} (e^{ax}\sin(bx)) \\
\end{align*}
Now we use the product rule to get
%
\begin{align*}
&\frac{d}{dx} (e^{ax} \cos(bx)) + i \frac{d}{dx} (e^{ax}\sin(bx)) \\
&= ae^{ax} \cos(bx) - be^{ax}\sin(bx) +
   i (a e^{ax}\sin(bx) + b e^{ax}\cos(bx)) \\
&= e^{ax}(a \cos(bx) - b\sin(bx) + i (a \sin(bx) +  b \cos(bx))
\end{align*}
%
On the other hand,
%
\begin{align*}
w e^{wx}
&= (a + bi) e^{ax + bxi} \\
&= (a + bi) e^{ax} (\cos(bx) + i \sin(bx)) \\
&= e^{ax} (a + bi)(\cos(bx) + i \sin(bx)) \\
&= e^{ax} ((a\cos(bx) - b\sin(bx)) + i ( a\sin(bx)) + b\cos(bx))
\end{align*}
as required.
\end{proof}

That Theorem~\ref{thm:polar:e_differentiation} is true is pretty
amazing. It is what really gets complex analysis going.

\begin{example}
Here is another amusing fact (if only for its obfuscating effect):
$1 = -e^{i\pi}$.
\end{example}

\begin{proof}[Solution]
By definition, we have
$e^{i\pi} = \cos(\pi) + i \sin(\pi) = -1 + i 0 = -1$.
\end{proof}


%%-----------------------------------------------------------------------%%
%%--- Trigonometry and complex exponentials -----------------------------%%

\subsection{Trigonometry and complex exponentials}
\index{trigonometry!and complex exponentials}

Trigonometric functions can also be expressed in terms of the complex
exponential. Then \emph{everything} involving trig functions can be
transformed into something involving the exponential function. This is
very surprising.

In order to easily obtain trigonometric identities like
$\cos(x)^2 + \sin(x)^2 = 1$, let us write $\cos(x)$ and $\sin(x)$ as
complex exponentials. From the definitions, we have
\[
e^{ix} = \cos(x) + i\sin(x)
\]
so
\[
e^{-ix}
=
\cos(-x) + i\sin(-x)
=
\cos(x) - i\sin(x).
\]
Adding these two equations and dividing by $2$ yields a formula for
$\cos(x)$, and subtracting and dividing by $2i$ gives a formula for
$\sin(x)$:
%
\begin{equation}
\label{eqn:polar:sin_cos_exponentials}
\cos(x) = \frac{e^{ix} + e^{-ix}}{2}
\qquad
\sin(x) = \frac{e^{ix} - e^{-ix}}{2i}.
\end{equation}

We can now derive trigonometric identities. For example,
%
\begin{align*}
\sin(2x)
&= \frac{e^{i2x} - e^{-i2x}}{2i} \\
&= \frac{(e^{ix} - e^{-ix}) (e^{ix} + e^{-ix})}{2i} \\
&= 2 \frac{e^{ix} - e^{-ix}}{2i} \frac{e^{ix} + e^{-ix}}{2} \\
&= 2 \sin(x) \cos(x).
\end{align*}
%
This is not at all impressive, given that we can get this much more
directly using
\[
(\cos(2x) + i\sin(2x))
=
(\cos(x) + i\sin(x))^2
=
\cos^2(x) - \sin^2(x) + i2\cos(x)\sin(x)
\]
and equating imaginary parts. But there are more interesting examples.

Next, we verify that~(\ref{eqn:polar:sin_cos_exponentials}) implies
that $\cos(x)^2 + \sin(x)^2 = 1$. We have
%
\begin{align*}
4(\cos(x)^2 + \sin(x)^2)
&= \left( e^{ix} + e^{-ix} \right)^2 +
   \left( \frac{e^{ix} - e^{-ix}}{i} \right)^2 \\
&= e^{2ix} + 2 + e^{-2ix} - (e^{2ix} - 2 + e^{-2ix}) \\
&= 4.
\end{align*}
The equality just appears as a follow-your-nose algebraic
calculation.

\begin{figure}[!htbp]
\centering
\begin{tikzpicture}
[linestyle/.style={semithick},%
  axisstyle/.style={semithick,->,>=stealth}]
% horizontal and vertical axes
\draw[axisstyle] (-0.1,0) -- (6.5,0) node[right]{$x$};
\draw[axisstyle] (0,-1.2) -- (0,1.5) node[above]{$y$};
% tick marks on horizontal axis
\draw[linestyle] (2,-0.1) node[below]{2}-- (2,0.1);
\draw[linestyle] (4,-0.1) -- (4,0.1) node[above]{4};
\draw[linestyle] (6,-0.1) node[below]{6}-- (6,0.1);
% tick marks on vertical axis
\draw[linestyle] (-0.1,-1) node[left]{$-1$}-- (0.1,-1);
\draw[linestyle] (-0.1,1) node[left]{1}-- (0.1,1);
% graph of function
\draw[linestyle] plot[domain=0:6.2831] function{sin(x)**3};
\end{tikzpicture}
\caption{Plot of $y = \sin(x)^3$ for $0 \leq x \leq 2\pi$.}
\label{fig:polar:sin_x_cube}
\end{figure}

\begin{example}
Compute $\sin(x)^3$ as a sum of sines and cosines with no powers.
\end{example}

\begin{proof}[Solution]
%\fig{What is $\sin(x)^3$?\label{fig:sin3}}{example_sin3}
We use (\ref{eqn:polar:sin_cos_exponentials}):
%
\begin{align*}
\sin(x)^3
&= \left( \frac{e^{ix} - e^{-ix}}{2i} \right)^3 \\
&= \left( \frac{1}{2i} \right)^3 (e^{ix} - e^{-ix})^3 \\
&= \left( \frac{1}{2i} \right)^3
   (e^{ix} - e^{-ix}) (e^{ix} - e^{-ix})(e^{ix} - e^{-ix}) \\
&= \left( \frac{1}{2i} \right)^3
   (e^{ix} - e^{-ix})(e^{2ix} - 2 + e^{-2ix}) \\
&= \left( \frac{1}{2i} \right)^3
   (e^{3ix} - 2e^{ix} + e^{-ix} - e^{ix} + 2e^{-ix} - e^{-3ix}) \\
&= \left( \frac{1}{2i} \right)^3
   ((e^{3ix} - e^{-3ix}) -  3(e^{ix} - e^{-ix})) \\
&= -\left( \frac{1}{4} \right) \left[
   \frac{e^{3ix} - e^{-3ix}}{2i} -  3 \cdot \frac{e^{ix} -e^{-ix}}{2i}
   \right] \\
&= \frac{3\sin(x) - \sin(3x)}{4}.
\end{align*}
%
You can also do this in \sage:
%
\begin{center}
\fontsize{10pt}{10pt}
\selectfont
\tt
\begin{lstlisting}
sage: y = sin(x)^3
sage: maxima(y).trigreduce()
(3*sin(x)-sin(3*x))/4
\end{lstlisting}
\end{center}
%
Figure~\ref{fig:polar:sin_x_cube} contains a plot of $y = \sin(x)^3$
for $0 \leq x \leq 2\pi$.
\end{proof}


%%-----------------------------------------------------------------------%%
%%--- Integrals of trigonometric functions ------------------------------%%

\section{Integrals of trigonometric functions}
\label{sec:trigint}
\index{trigonometry!integrals}

There are an overwhelming number of combinations of trigonometric
functions that appear in integrals. Fortunately, they fall into a few
patterns and most of their integrals can be found using reduction
formulas and tables of integrals. This section examines some of the
patterns of these combinations and illustrates how some of their
integrals can be derived.


%%-----------------------------------------------------------------------%%
%%--- Products of sine and cosine ---------------------------------------%%

\subsection{Products of sine and cosine}
\index{trigonometry!products of sine and cosine}

Consider the integrals
\[
\int \sin(ax)\sin(bx) \, dx,\quad
\int \cos(ax)\cos(bx) \, dx,\quad
\int \sin(ax)\cos(bx) \, dx.
\]
All of these integrals are handled by referring to the trigonometric
identities for sine and cosine of sums and differences:
%
\begin{align*}
\sin(A + B) &= \sin(A)\cos(B) + \cos(A)\sin(B) \\
\sin(A - B) &= \sin(A)\cos(B) - \cos(A)\sin(B) \\
\cos(A + B) &= \cos(A)\cos(B) - \sin(A)\sin(B) \\
\cos(A - B) &= \cos(A)\cos(B) + \sin(A)\sin(B).
\end{align*}
%
By adding or subtracting the appropriate pairs of identities, we can
write the various products such as $\sin(ax)\cos(bx)$ as a sum or
difference of single sines or cosines. For example, by adding the
first two identities we get
$2\sin(A)\cos(B) = \sin(A + B) + \sin(A - B)$ so
$\sin(A)\cos(B) = 2 { \sin(A+B) + \sin(A-B)}$. Using this last
identity, the integral of $\sin(ax)\cos(bx)$ for $a \not= b$ is
relatively easy:
%
\begin{align*}
\int \sin(ax)\cos(bx) \, dx
&= \int \frac{1}{2} \big( \sin((a + b)x) + \sin((a - b)x) \big) \, dx \\
&= \frac{1}{2} \left[
   \frac{-\cos((a - b)x)}{a - b} + \frac{-\cos((a + b)x)}{a + b} \right] + C.
\end{align*}
The other integrals of products of sine and cosine follow in a similar manner.

For $a \neq b$:
%
\boxedeqnalign{
\int \sin(ax)\sin(bx) \, dx
&= \frac{1}{2} \left[
   \frac{\sin((a - b)x)}{a - b} - \frac{\sin((a + b)x)}{a + b} \right] + C \\
\int \cos(ax)\cos(bx) \, dx
&= \frac{1}{2} \left[
   \frac{\sin((a - b)x)}{a - b} + \frac{\sin((a + b)x)}{a + b} \right] + C \\
\int \sin(ax)\cos(bx) \, dx
&= -\frac{1}{2} \left[
   \frac{\cos((a - b)x)}{a - b} + \frac{\cos((a + b)x)}{a + b} \right] + C
}
%
This is confirmed by \sage:
%
\begin{center}
\fontsize{10pt}{10pt}
\selectfont
\tt
\begin{lstlisting}
sage: a, b = var("a, b")
sage: integral(sin(a*x) * cos(b*x), x)
-((b - a)*cos((b + a)*x) + (-b - a)*cos((b - a)*x))/(2*b^2 - 2*a^2)
sage: integral(sin(a*x) * sin(b*x), x)
-((b - a)*sin((b + a)*x) + (-b - a)*sin((b - a)*x))/(2*b^2 - 2*a^2)
sage: integral(cos(a*x) * cos(b*x), x)
((b - a)*sin((b + a)*x) + (b + a)*sin((b - a)*x))/(2*b^2 - 2*a^2)
\end{lstlisting}
\end{center}
%
For $a=b$:
%
\boxedeqnalign{
\int \sin(ax)^2 \, dx
&= \frac{x}{2} - \frac{\sin(ax)\cos(ax)}{2a} + C \\
\int \cos(ax)^2 \, dx
&= \frac{x}{2} + \frac{\sin(ax)\cos(ax)}{2a} + C \\
\int \sin(ax)\cos(ax) \, dx
&= \frac{\sin(ax)^2}{2a} + C
}
%
The first and second of these integral formulas follow from the
identities $\sin (ax)^2 = \frac{1 - \cos(2ax)}{2}$ and
$\cos(ax)^2 = \frac{1 + \cos(2ax)}{2}$. The third can be derived
by a substitution using the variable $u = \sin(ax)$. These formulas
too are confirmed by \sage:
%
\begin{center}
\fontsize{10pt}{10pt}
\selectfont
\tt
\begin{lstlisting}
sage: a = var("a")
sage: integral(cos(a*x)^2, x)
(sin(2*a*x) + 2*a*x)/(4*a)
sage: integral(sin(a*x)^2, x)
-(sin(2*a*x) - 2*a*x)/(4*a)
sage: integral(sin(a*x) * cos(a*x), x)
-cos(a*x)^2/(2*a)
\end{lstlisting}
\end{center}

\begin{remark}
\sage tells us that
$\int \sin(ax)\cos(ax) \, dx = -\frac{\cos(ax)^2}{2a} + C$,
but the table tells us that
$\int \sin(ax)\cos(ax) \, dx = \frac{\sin(ax)^2}{2a} + C$. Aside from
the ambiguity in the notation ``$+C$'', these are the same since
$\sin(ax)^2 = -\cos(ax) + 1$. In other words, if you keep in mind that
``$+C$'' in one equation is not the same as ``$+C$'' in another, these
formulas are the same.
\end{remark}

\begin{example}
Compute $\int \sin^3(x) \, dx$.
\end{example}

\begin{proof}[Solution]
We use trigonometric identities and compute the integral directly as
follows:
%
\begin{align*}
\int \sin^3(x) \, dx
&= \int \sin^2(x) \sin(x) \, dx \\
&= \int \big( 1 - \cos^2(x) \big) \sin(x) \, dx \\
&= -\cos(x) + \frac{1}{3} \cos^3(x) + c
   \qquad\text{(substitution $u = \cos(x)$)}.
\end{align*}
%
This idea always works for \emph{odd} powers of $\sin(x)$.
\end{proof}

\begin{example}
What about \emph{even} powers? Compute $\int \sin^4(x) \, dx$.
\end{example}

\begin{proof}[Solution]
We have
%
\begin{align*}
\sin^4(x)
&= \big( \sin^2(x) \big)^2 \\
&= \left[ \frac{1 - \cos(2x)}{2} \right]^2 \\
&= \frac{1}{4} \cdot \big(
   1 - 2\cos(2x) + \cos^2(2x) \big) \\
&= \frac{1}{4} \left[
   1 - 2\cos(2x) + \frac{1}{2} + \frac{1}{2} \cos(4x) \right].
\end{align*}
%
Thus
%
\begin{align*}
\int \sin^4(x) \, dx
&= \int \left[ \frac{3}{8} - \frac{1}{2} \cos(2x) +
   \frac{1}{8} \cos(4x) \right] \, dx \\
&= \frac{3}{8} x - \frac{1}{4} \sin(2x) + \frac{1}{32} \sin(4x) + C.
\end{align*}
Here is the key trick: Realize that we should write
$\sin^4(x)$ as $(\sin^2(x))^2$, and the rest is straightforward.
\end{proof}


%%-----------------------------------------------------------------------%%
%%--- Powers of sine and cosine -----------------------------------------%%

\subsection{Powers of sine and cosine}
\index{trigonometry!powers of sine and cosine}

Here, we consider patterns for the integral
$\int \sin (x)^m \cos(x)^n \, dx$. If the exponent of sine is
\emph{odd}, we can split off one factor $\sin(x)$ and use the
trigonometric identity $\sin(x)^2 = 1 - \cos(x)^2$ to rewrite the
remaining even power of sine in terms of cosine. Then the change of
variable $u = \cos(x)$ makes all of the integrals
straightforward. Similarly, if the exponent of cosine is \emph{odd},
we can split off one factor $\cos(x)$ and use the trigonometric
identity $\cos(x)^2 = 1 - \sin(x)^2$ to rewrite the remaining even
power of sine in terms of cosine. Then the change of variable
$u = \sin(x)$ makes all of the integrals straightforward. If both
exponents are even, we can use the identities
\[
\sin (x)^2 = \frac{1 - \cos(2x)}{2}
\qquad\text{and}\qquad
\cos (x)^2 = \frac{1 + \cos(2x)}{2}
\]
to rewrite the integral in terms of powers of $\cos(2x)$ and then
proceed with integrating even powers of cosine.

\begin{example}
This example illustrates a method for computing integrals of
trigonometric functions that does not require knowing any
trigonometric identities at all or any tricks. It is very tedious,
though. Compute $\int \sin^3(x) \, dx$ using complex exponentials.
\end{example}

\begin{proof}[Solution]
We have
\[
\cos(x) = \frac{e^{ix} + e^{-ix}}{2}
\qquad
\sin(x) = \frac{e^{ix} - e^{-ix}}{2i}
\]
hence
%
\begin{align*}
\int \sin^3(x) \, dx
&= \int \left( \frac{e^{ix} - e^{-ix}}{2i} \right)^3 \, dx \\
&= -\frac{1}{8i} \int (e^{ix} - e^{-ix})^3 \, dx \\
&= -\frac{1}{8i} \int (e^{ix} - e^{-ix})(e^{ix} -
   e^{-ix})(e^{ix} - e^{-ix}) \, dx\\
&= -\frac{1}{8i} \int (e^{2ix} -2 + e^{-2ix})(e^{ix} - e^{-ix}) \, dx \\
&= -\frac{1}{8i} \int e^{3ix} - e^{ix} - 2e^{ix} + 2e^{-ix}
   + e^{-ix} - e^{-3ix} \, dx \\
&= -\frac{1}{8i} \int e^{3ix} - e^{-3ix} + 3e^{-ix} - 3e^{ix} \,  dx \\
&= -\frac{1}{8i} \left(
   \frac{e^{3ix}}{3i} - \frac{e^{-3ix}}{-3i} +
   \frac{3e^{-ix}}{-i} - \frac{3e^{ix}}{i} \right) + C \\
&= \frac{1}{4} \left( \frac{1}{3} \cos(3x) - 3\cos(x) \right) + C \\
&= \frac{1}{12} \cos(3x) - \frac{3}{4}\cos(x) + C.
\end{align*}
%
The answer looks totally different, but is in fact the same function.
\end{proof}

\begin{example}
The complex exponentials method used in the previous example also
works for powers of different trigonometric functions. Compute
$\int \sin^3(x) \cos^2(x) \, dx$.
\end{example}

\begin{proof}[Solution]
This is straightforward:
%
\begin{align*}
&\int \sin^3(x) \cos^2(x) \, dx \\
&= \int \left( \frac{e^{ix} - e^{-ix}}{2i} \right)^3
   \left( \frac{e^{ix} + e^{-ix}}{2} \right)^2 \, dx \\
&= \int \frac{-ie^{5ix}}{32} + \frac{ie^{3ix}}{32} + \frac{ie^{ix}}{16} -
   \frac{ie^{-ix}}{16} - \frac{ie^{-3ix}}{32} + \frac{ie^{-5ix}}{32} \, dx \\
&= \frac{-e^{5ix}}{160} + \frac{e^{3ix}}{96} + \frac{e^{ix}}{16} +
    \frac{e^{-ix}}{16} + \frac{e^{-3ix}}{96} - \frac{e^{-5ix}}{160} + C \\
&= \left( \frac{-e^{5ix}}{160} - \frac{e^{-5ix}}{160} \right) +
   \left( \frac{e^{3ix}}{96} + \frac{e^{-3ix}}{96} \right) +
   \left( \frac{e^{ix}}{16} + \frac{e^{-ix}}{16} \right) + C \\
&= -\frac{\cos(5x)}{80} + \frac{\cos(3x)}{32} + \frac{\cos(x)}{8} + C.
\end{align*}
%
It is tedious, but it works.
\end{proof}

Here are some more identities that we will use in illustrating some
tricks below.
%
\begin{equation}
\frac{d}{dx} \tan(x) = \sec^2(x)
\end{equation}
%
and
%
\begin{equation}
\frac{d}{dx} \sec(x) = \sec(x)\tan(x).
\end{equation}
%
Also
%
\begin{equation}
1 + \tan^2(x) = \sec^2(x).
\end{equation}

\begin{example}
Compute $\int \tan^3(x) \, dx$.
\end{example}

\begin{proof}[Solution]
We have
%
\begin{align*}
\int \tan^3(x) \, dx
&= \int\tan(x) \tan^2(x) \, dx \\
&= \int \tan(x) \big( \sec^2(x) - 1 \big) \, dx \\
&= \int \tan(x) \sec^2(x) \, dx - \int \tan(x) \, dx \\
&= \frac{1}{2} \tan^2(x) - \ln|\sec(x)| + C.
\end{align*}
%
Here, we used the substitution $u = \tan(x)$, so
$du = \sec^2(x) \, dx$. Then
\[
\int \tan(x) \sec^2(x) \, dx
=
\int u \, du
=
\frac{1}{2} u^2 + C
=
\frac{1}{2} \tan^2(x) + C.
\]
Also, with the substitution $u = \cos(x)$ and $du = -\sin(x) \, dx$,
we get
\[
\int \tan(x) \, dx
=
\int \frac{\sin(x)}{\cos(x)} \, dx
=
-\int \frac{1}{u} \, du
=
-\ln|u| + C
=
-\ln|\sec(x)| + C.
\]
Here is the key trick: Write $\tan^3(x)$ as $\tan(x) \tan^2(x)$.
\end{proof}

\begin{example}
Here is one that combines trigonometric identities with the funnest
variant of integration by parts. Compute $\int \sec^3(x) \, dx$.
\end{example}

\begin{proof}[Solution]
We have
\[
\int \sec^3(x) \, dx
=
\int \sec(x) \sec^2(x) \, dx.
\]
Let's use integration by parts:
%
\begin{align*}
u  &= \sec(x)              & v  &= \tan(x) \\
du &= \sec(x)\tan(x) \, dx & dv &= \sec^2(x) \, dx.
\end{align*}
%
The above integral becomes
%
\begin{align*}
\int \sec(x) \sec^2(x) \, dx
&= \sec(x) \tan(x) - \int \sec(x) \tan^2(x) \, dx \\
&= \sec(x) \tan(x) - \int \sec(x) \big( \sec^2(x) - 1 \big) \, dx \\
&= \sec(x) \tan(x) - \int \sec^3(x) + \int \sec(x) \, dx \\
&= \sec(x) \tan(x) - \int \sec^3(x) + \ln|\sec(x) + \tan(x)| \, dx.
\end{align*}
%
This is familiar. Solving for $\int \sec^3(x) \, dx$, we get
\[
\int \sec^3(x) \, dx
=
\frac{1}{2} \big(
\sec(x) \tan(x) + \ln|\sec(x) + \tan(x)| \big) + C
\]
as required.
\end{proof}


%%-----------------------------------------------------------------------%%
%%--- Some remarks on using complex-valued functions --------------------%%

\subsection{Some remarks on using complex-valued functions}
\index{complex-valued functions}

Consider functions of the form
%
\begin{equation}
\label{eqn:ri}
f(x) + i g(x)
\end{equation}
%
where $x$ is a real variable and $f,g$ are real-valued functions. For
example,
\[
e^{ix} = \cos(x) + i \sin(x).
\]
We observed before that
\[
\frac{d}{dx} e^{wx} = w e^{wx}
\]
hence
\[
\int e^{wx}dx = \frac{1}{w} e^{wx} + C.
\]
For example, writing $e^{ix}$ as in~(\ref{eqn:ri}), we have
%
\begin{align*}
\int e^{ix} \, dx
&= \int \cos(x) \, dx + i \int \sin(x) \, dx \\
&= \sin(x) - i \cos(x) + C \\
&= -i (\cos(x) + i \sin(x)) + C \\
&= \frac{1}{i} e^{ix}.
\end{align*}

%\forclass{Correct something in the supplement as
%an example... (look up what exactly was wrong)}
\begin{example}
Compute $\int \frac{1}{x+i} \, dx$.
\end{example}

\begin{proof}[Solution]
Wouldn't it be nice if we could just write $\ln (x+i) + C$? This is
useless for us, though, since we have not even \emph{defined}
$\ln (x+i)$! However, we can ``rationalize the denominator'' by writing
%
\begin{align*}
\int \frac{1}{x+i} \, dx
&= \int \frac{1}{x+i} \cdot \frac{x-i}{x-i} \, dx \\
&= \int \frac{x-i}{x^2 + 1} \, dx \\
&= \int \frac{x}{x^2 + 1} \, dx - i \int \frac{1}{x^2 + 1} \, dx \\
&= \frac{1}{2} \ln|x^2 + 1| - i \tan^{-1}(x) + C.
\end{align*}
%
This informs how we would define $\ln(z)$ for $z$ complex (which you
would do if you take a course in complex analysis). The key trick is:
Get the $i$ in the numerator.
\end{proof}

The next example illustrates an alternative to the method
of Section~\ref{sec:trigint}.

\begin{example}
Compute $\int \sin(5x) \cos(3x) \, dx$.
\end{example}

\begin{proof}[Solution]
We have
%
\begin{align*}
\int \sin(5x) \cos(3x) \, dx
&= \int \left(\frac{e^{i5x} - e^{-i5x}}{2i} \right) \cdot \left(
   \frac{e^{i5x} + e^{-i5x}}{2} \right) \, dx \\
&= \frac{1}{4i} \int \left(
   e^{i8x} - e^{-i8x} + e^{i2x} - e^{-i2x} \right) \, dx + C \\
&= \frac{1}{4i} \left(
   \frac{e^{i8x}}{8i} + \frac{e^{-i8x}}{8i} + \frac{e^{i2x}}{2i} +
   \frac{e^{-i2x}}{2i} \right) + C \\
&= -\frac{1}{4} \left( \frac{1}{4} \cos(8x) + \cos(2x) \right) + C.
\end{align*}
%
This \emph{is} more tedious than the method in
Section~\ref{sec:trigint}. But it is
\emph{completely straightforward}. You do not need any trigonometric
formulas or anything else. You just multiply it out, integrate,
etc. and keeping in mind that $i^2 = -1$.
\end{proof}
